package com.redside.webapp.util;

import java.beans.PropertyEditorSupport;

import com.redside.Constants;
import com.redside.model.lookup.ComplaintStatusLkp;
import com.redside.service.OptionsBeanLookupManager;

public class CustomComplaintStatusLookupEditor  extends PropertyEditorSupport {
 
    private final OptionsBeanLookupManager optionsBeanManager;
 
    public CustomComplaintStatusLookupEditor(OptionsBeanLookupManager optionsBeanLookupDao) {
        this.optionsBeanManager = optionsBeanLookupDao;
    }
 
    @Override
    public void setAsText(String text) throws IllegalArgumentException {
    	//TODO fix to get value from text field
    	ComplaintStatusLkp lkp = new ComplaintStatusLkp(optionsBeanManager.findById(Constants.COMPLAINT_STATUS, "1"));
        setValue(lkp);
    }
 
    @Override
    public String getAsText() {
    	ComplaintStatusLkp s = (ComplaintStatusLkp) getValue();
        if (s == null) {
            return null;
        } else {
            return s.getId().toString();
        }
    }
}